const calculate = (s) => {
  const nums = [];
  let prevOps = "+";
  let cur = 0;
  s = s + "+";
  for (let i = 0; i < s.length; i++) {
    if (s[i] >= "0" && s[i] <= "9") {
      cur = cur * 10 + s[i].charCodeAt() - "0".charCodeAt();
    } else if (s[i] === " ") {
      continue;
    } else {
      if (prevOps === "+") {
        nums.push(cur);
      } else if (prevOps === "-") {
        nums.push(-1 * cur);
      } else if (prevOps === "*") {
        nums[nums.length - 1] *= cur;
      } else if (prevOps === "/") {
        nums[nums.length - 1] = (nums[nums.length - 1] / cur) | 0;
      }
      prevOps = s[i];
      cur = 0;
    }
  }
  let sum = 0;
  nums.forEach((v) => {
    sum += v;
  });
  return sum;
};
